#include "gtest/gtest.h"

#include "Buffer.h"

using namespace frame;

TEST(BufferTest, use){
	Buffer rb;
	ASSERT_EQ(Buffer::kBufferLength, rb.capacity());

	const char * str = "hello";
	size_t len = strlen(str);
	ASSERT_TRUE(rb.freeBytes() >= len);
	ASSERT_EQ(len, rb.putBytes(str, len));
	ASSERT_EQ(Buffer::kBufferLength - len, rb.freeBytes());


	int readBytes = 3;
	ASSERT_TRUE(rb.inBytes() >= readBytes);
	char buf[8] = {0};
	ASSERT_EQ(readBytes, rb.getBytes(buf, readBytes));
	ASSERT_STREQ("hel", buf);

	rb.compact(); // or rb.reset();
	ASSERT_EQ(0, rb.TEST_position());
	ASSERT_EQ(len - readBytes, rb.TEST_limit());

	rb.reset();
	ASSERT_EQ(0, rb.TEST_position());
	ASSERT_EQ(0, rb.TEST_limit());

	rb.fakePut(len);
	ASSERT_EQ(len, rb.inBytes());
	ASSERT_EQ(Buffer::kBufferLength - len, rb.freeBytes());

	rb.fakeGet(len);
	ASSERT_EQ(0, rb.inBytes());
	ASSERT_EQ(Buffer::kBufferLength - len, rb.freeBytes());
}


//TODO: 
//   asyncReadCallback(IBufferImpl::Ptr rb)
TEST(BufferTest, asioUse){
}
